﻿using System;
using System.Collections.ObjectModel;

namespace Transportr
{
    public class FavoriteRoutesModel
    {
        public ObservableCollection<RouteItemViewModel> Items { get; private set; }
        public bool IsDataLoaded { get; private set; }

        public FavoriteRoutesModel()
        {
            this.Items = new ObservableCollection<RouteItemViewModel>();
            FavoriteStore.Update += (s) => { BeginUpdate(); };
            this.BeginUpdate();
        }

        public void BeginUpdate()
        {
            IsDataLoaded = false;
            Items.Clear();
            if (FavoriteStore.Valid && FavoriteStore.Store.Routes != null)
            {
                foreach (FavoriteStore.Route l in FavoriteStore.Store.Routes)
                {
                    Items.Add(new RouteItemViewModel()
                    {
                        RouteId = l.Id,
                        RouteName = l.Name
// TODO
                    });

                }
                IsDataLoaded = true;
            }
        }
    }
}
